package com.example.perpetualcalendar.ui.fragment.calendar;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.perpetualcalendar.data.network.AppSchedulerProvider;
import com.example.perpetualcalendar.domain.entity.Calendar;
import com.example.perpetualcalendar.domain.entity.History;
import com.example.perpetualcalendar.domain.usecase.CalendarUseCase;
import com.example.perpetualcalendar.ui.fragment.history.HistoryRepository;
import com.example.perpetualcalendar.viewModel.BaseViewModel;

import io.reactivex.observers.DisposableObserver;

/**
 * @author langhua
 */
public class CalendarViewModel extends BaseViewModel<CalendarUseCase> {

    private MutableLiveData<Calendar.ResultDTO.DataDTO> mDto;

    public CalendarViewModel() {
        mDto = new MutableLiveData<>();
        calendar("");
    }

    @NonNull
    @Override
    protected CalendarUseCase setUseCase() {
        return new CalendarUseCase(AppSchedulerProvider.getInstance(), new CalendarRepository());
    }
    public void calendar(String date) {
        assert useCase != null;
        useCase.execute(new DisposableObserver<Calendar>() {
            @Override
            public void onNext(Calendar calendar) {
                if(calendar!=null&&calendar.getResult()!=null&&calendar.getResult().getData()!=null){
//                    Log.d("TAG", "onNext: "+calendar.getResult().getData().getDate());
                    mDto.postValue(calendar.getResult().getData());
                }
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        },useCase.calendarApi(date));
    }
    public LiveData<Calendar.ResultDTO.DataDTO> getDto() {
        return mDto;
    }
}